package org.game.db.bean;

import org.game.db.cache.PlayerActivityCache;
import com.sojoys.artifact.factory.bytebuff.IByteBuff;
import org.apache.commons.lang3.ArrayUtils;
import com.sojoys.artifact.build.data.base.BasePojo;
import java.sql.SQLException;
import java.util.List;
import static org.game.db.StaticResource.PlayerActivityResource.*;
import com.sojoys.artifact.tools.ToolMap;
import com.sojoys.artifact.tools.SK_Plus;
import com.sojoys.artifact.tools.ToolCopy;
import org.game.db.cache.PlayerCache;
import java.sql.ResultSet;
import java.util.Map;
import com.alibaba.fastjson.JSONObject;
import com.sojoys.artifact.constant.DataModelKeyEnum;
import static org.game.db.StaticResource.PlayerActivityResource.*;
/**
 * 玩家活动记录
 */
public class PlayerActivity extends BasePojo<PlayerActivity> implements org.game.db.vo.BaseActivity{
	
	
	/**
	 * 索引值
	 */
	private String[] indexValues = new String[4];
	
	/**
	* id
	*/
	private long id;
	
	/**
	* 活动ID
	*/
	private int activityId;
	
	/**
	* 版本号
	*/
	private int ver;
	
	/**
	* 玩家ID
	*/
	private int playerId;
	
	/**
	* 扩展数据(比如已经签到第几天)
	*/
	private Map extend;
	
	/**
	* 条目
	*/
	private Map entry;
	
	/**
	* create_date
	*/
	private java.util.Date createDate;
	
	/**
	* modified_date
	*/
	private java.util.Date modifiedDate;
	
	
	@Deprecated
	public static PlayerActivity builder() {
		PlayerActivity playerActivity = new PlayerActivity();
		return playerActivity;
	}
	
	@Deprecated
	public PlayerActivity() {
		super();
	}
	
	public PlayerActivity(long id, int activityId, int ver, int playerId, Map extend, Map entry) {
		super();
		this.id = id;
		this.activityId = activityId;
		this.ver = ver;
		this.playerId = playerId;
		this.extend = extend;
		this.entry = entry;
		this.createDate = new java.util.Date();
		this.modifiedDate = new java.util.Date();
	}
	
	/**
	 * id
	 */
	public long getId() {return id;}
	
	/**
	 * id
	 */
	public PlayerActivity setId(long id) {this.id = id;return this;}
	
	/**
	 * 活动ID
	 */
	public int getActivityId() {return activityId;}
	
	/**
	 * 活动ID
	 */
	public PlayerActivity setActivityId(int activityId) {this.activityId = activityId;return this;}
	
	/**
	 * 版本号
	 */
	public int getVer() {return ver;}
	
	/**
	 * 版本号
	 */
	public PlayerActivity setVer(int ver) {this.ver = ver;return this;}
	
	/**
	 * 玩家ID
	 */
	public int getPlayerId() {return playerId;}
	
	/**
	 * 玩家ID
	 */
	public PlayerActivity setPlayerId(int playerId) {this.playerId = playerId;return this;}
	
	/**
	 * 扩展数据(比如已经签到第几天)
	 */
	public Map getExtend() {return extend;}
	
	/**
	 * 扩展数据(比如已经签到第几天)
	 */
	public PlayerActivity setExtend(Map extend) {this.extend = extend;return this;}
	
	/**
	 * 扩展数据(比如已经签到第几天)
	 */
	public byte[] getExtendByte() {
		return toBytes(extend);
	}
	
	/**
	 * 扩展数据(比如已经签到第几天)
	 */
	public Map initExtendByte(byte[] _byte) {
		return (Map)forBytesObject(_byte);
	}	
	/**
	 * 条目
	 */
	public Map getEntry() {return entry;}
	
	/**
	 * 条目
	 */
	public PlayerActivity setEntry(Map entry) {this.entry = entry;return this;}
	
	/**
	 * 条目
	 */
	public byte[] getEntryByte() {
		return toBytes(entry);
	}
	
	/**
	 * 条目
	 */
	public Map initEntryByte(byte[] _byte) {
		return (Map)forBytesObject(_byte);
	}	
	/**
	 * create_date
	 */
	public java.util.Date getCreateDate() {return createDate;}
	
	/**
	 * create_date
	 */
	protected PlayerActivity setCreateDate(java.util.Date createDate) {this.createDate = createDate;return this;}
	
	/**
	 * modified_date
	 */
	public java.util.Date getModifiedDate() {return modifiedDate;}
	
	/**
	 * modified_date
	 */
	protected PlayerActivity setModifiedDate(java.util.Date modifiedDate) {this.modifiedDate = modifiedDate;return this;}
	
	
	// 代理
	
	protected Object[] getColumnNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return SOURCE_COLUMN_NAMES;
		case PINGYING:
			return PINGYING_COLUMN_NAMES;
		case HASHCODE:
			return HASHCODE_COLUMN_NAMES;
		case REMARKS:
			return SOURCE_COLUMN_REMARKS;
		default:
			return PINGYING_COLUMN_NAMES;
		}
	}
	
	protected Object[] getFKTableNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return FK_SOURCE_TABLE_NAMES;
		case PINGYING:
			return FK_PINGYING_TABLE_NAMES;
		case HASHCODE:
			return FK_HASHCODE_TABLE_NAMES;
		default:
			return FK_PINGYING_TABLE_NAMES;
		}
	}
	
	protected Object[] getFKColumnNames(DataModelKeyEnum e){
		switch (e) {
		case SOURCE:
			return FK_SOURCE_COLUMN_NAMES;
		case PINGYING:
			return FK_PINGYING_COLUMN_NAMES;
		case HASHCODE:
			return FK_HASHCODE_COLUMN_NAMES;
		default:
			return FK_PINGYING_TABLE_NAMES;
		}
	}
	
	protected String[] getBasicTypes(){
		return COLUMN_BASICTYPES;
	}
	
	protected Class[] getClassTypes(){
		return COLUMN_CLASSTYPES;
	}
	
	protected String[] getColumnTypes(){
		return COLUMN_COLUMNTYPES;
	}
	
	protected int getColumnCount(){
		return COLUMN_COUNT;
	}
	
	protected Object[] getColumeValues(){
		Object[] values = new Object[COLUMN_COUNT];
        values[0] = this.id;
        values[1] = this.activityId;
        values[2] = this.ver;
        values[3] = this.playerId;
        values[4] = this.extend;
        values[5] = this.entry;
        values[6] = this.createDate;
        values[7] = this.modifiedDate;
        return values;
	}
	
	public PlayerActivity deepCopy(){
		PlayerActivity playerActivity = null;
		try {
			playerActivity = (PlayerActivity) super.clone();
		    playerActivity.setExtend(ToolCopy.copyObject(this.extend));
		    playerActivity.setEntry(ToolCopy.copyObject(this.entry));
		    playerActivity.setCreateDate(ToolCopy.copyObject(this.createDate));
		    playerActivity.setModifiedDate(ToolCopy.copyObject(this.modifiedDate));
		    // 克隆索引
		    playerActivity.indexValues = ArrayUtils.clone(indexValues);
			return playerActivity;
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		return playerActivity;
	}
	
	
	protected Map<Object, Object> toMap(Object[] keys,Map<Object, Object> map){
        map.put(keys[0], this.id);
        map.put(keys[1], this.activityId);
        map.put(keys[2], this.ver);
        map.put(keys[3], this.playerId);
        map.put(keys[4], this.extend);
        map.put(keys[5], this.entry);
        map.put(keys[6], this.createDate);
        map.put(keys[7], this.modifiedDate);
        return map;
    }
    
    protected PlayerActivity createForMap(Object[] keys,Map map){
   		this.id = (long)map.get(keys[0]);
   		this.activityId = (int)map.get(keys[1]);
   		this.ver = (int)map.get(keys[2]);
   		this.playerId = (int)map.get(keys[3]);
   		this.extend = (Map)map.get(keys[4]);
   		this.entry = (Map)map.get(keys[5]);
   		this.createDate = (java.util.Date)map.get(keys[6]);
   		this.modifiedDate = (java.util.Date)map.get(keys[7]);
        return this;
    }
	
	
	protected JSONObject toJSONObject(Object[] keys,JSONObject obj){
        obj.put(keys[0], this.id);
        obj.put(keys[1], this.activityId);
        obj.put(keys[2], this.ver);
        obj.put(keys[3], this.playerId);
        obj.put(keys[4], toBytes(extend));
        obj.put(keys[5], toBytes(entry));
        obj.put(keys[6], this.createDate);
        obj.put(keys[7], this.modifiedDate);
        return obj;
    }
    
    protected PlayerActivity createForJSONObject(Object[] keys,JSONObject obj){
	    this.id = obj.getLongValue(keys[0]);
	    this.activityId = obj.getIntValue(keys[1]);
	    this.ver = obj.getIntValue(keys[2]);
	    this.playerId = obj.getIntValue(keys[3]);
		this.extend = (Map)forBytesObject(obj.getBytes(keys[4]));
		this.entry = (Map)forBytesObject(obj.getBytes(keys[5]));
	    this.createDate = obj.getDate(keys[6]);
	    this.modifiedDate = obj.getDate(keys[7]);
        return this;
    }
    
    
    public PlayerActivity createForResultSet(ResultSet rs) throws SQLException{
	    this.id = rs.getLong(SOURCE_COLUMN_NAMES[0]);
	    this.activityId = rs.getInt(SOURCE_COLUMN_NAMES[1]);
	    this.ver = rs.getInt(SOURCE_COLUMN_NAMES[2]);
	    this.playerId = rs.getInt(SOURCE_COLUMN_NAMES[3]);
		this.extend = (Map)forBytesObject(rs.getBytes(SOURCE_COLUMN_NAMES[4]));
		this.entry = (Map)forBytesObject(rs.getBytes(SOURCE_COLUMN_NAMES[5]));
	    this.createDate = rs.getTimestamp(SOURCE_COLUMN_NAMES[6]);
	    this.modifiedDate = rs.getTimestamp(SOURCE_COLUMN_NAMES[7]);
	    return this;
    }
    
    protected void writeBytes(IByteBuff byteBuf){
	    byteBuf.writeLong(this.id);
	    byteBuf.writeInt(this.activityId);
	    byteBuf.writeInt(this.ver);
	    byteBuf.writeInt(this.playerId);
	    byteBuf.writeObject(this.extend);
	    byteBuf.writeObject(this.entry);
	    byteBuf.writeDate(this.createDate);
	    byteBuf.writeDate(this.modifiedDate);
    }
	
	protected PlayerActivity readBytes(IByteBuff byteBuf){
	    this.id = byteBuf.readLong(null);
	    this.activityId = byteBuf.readInt(null);
	    this.ver = byteBuf.readInt(null);
	    this.playerId = byteBuf.readInt(null);
	    this.extend = (Map)byteBuf.readObject();
	    this.entry = (Map)byteBuf.readObject();
	    this.createDate = byteBuf.readDate(null);
	    this.modifiedDate = byteBuf.readDate(null);
	    return this;
	}
    
    
    protected JSONObject exportFKTableMap(Object[] keys,JSONObject map,DataModelKeyEnum e){
        return map;
    }
    
    protected boolean importFKTableMap(Object[] keys,JSONObject map,DataModelKeyEnum e){
		return true;
    }
    
	/** 取得[player]*/
	public Player getPlayerPkPlayerId(){
		return PlayerCache.me().getById(playerId);
	}
	
    /** 级联删除(延迟入库) */
    public boolean deleteAndSon(){
    	return false;
    }
    
    /** 级联删除(及时入库) */
    public boolean deleteAndSonAndFlush(){
    	return false;
    }
    
    /** 延迟插入数据库 */
    public PlayerActivity insert(){
    	return PlayerActivityCache.me().insert(this);
    }
    /** 延迟更新数据库 */
    public PlayerActivity update(){
    	return PlayerActivityCache.me().update(this);
    }
    /** 延迟删除数据库 */
    public boolean delete(){
    	return PlayerActivityCache.me().delete(this);
    }
    /** 即时插入数据库 */
    public PlayerActivity insertAndFlush(){
    	return PlayerActivityCache.me().insertAndFlush(this);
    }
    /** 即时更新数据库 */
    public PlayerActivity updateAndFlush(){
    	return PlayerActivityCache.me().updateAndFlush(this);
    }
    /** 即时删除数据库 */
    public boolean deleteAndFlush(){
    	return PlayerActivityCache.me().deleteAndFlush(this);
    }
    
    
	
	/**
	 * 同步索引值
	 */
	public PlayerActivity syncIndexValues(){
		indexValues[0] = SK_Plus.b(getId()).e();
		indexValues[1] = SK_Plus.b(getActivityId(),"_",getPlayerId()).e();
		indexValues[2] = SK_Plus.b(getActivityId()).e();
		indexValues[3] = SK_Plus.b(getPlayerId()).e();
		return this;
	}
	/**
	 * 取得索引
	 */
	public String[] getIndexValues(){
		return indexValues;
	}
	
	protected Object getPrimaryKey(){
		return getId();
	}
	
	protected void setPrimaryKey(Object key){
		setId((long)key);
	}
//自定义内容起始位置
//自定义内容结束位置
}